package com.young.springdemo.service.feign;


import com.sun.org.apache.regexp.internal.RE;
import com.young.springdemo.utils.DemoResp;
import com.young.springdemo.utils.ResponseData;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

@FeignClient(name = "feignSerive", url = "192.168.100.52:16010/myapi")
public interface FeignService {

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    @ResponseBody
    ResponseData<String> invoke();

    @RequestMapping(value = "getParam",method = RequestMethod.GET)
    String getParam(@RequestParam(value = "name") String name,@RequestParam(value = "age")String age);

    @RequestMapping(value = "getPost",method = RequestMethod.POST)
    String getPost();

    @RequestMapping(value = "getPostParam",method = RequestMethod.POST)
    String getPostParam(@RequestParam(value = "name")String name);

    @RequestMapping(value = "getPostResult",method = RequestMethod.POST)
    ResponseData<DemoResp> getPostResult();

    @RequestMapping(value = "getPostParamResult",method = RequestMethod.POST)
    ResponseData<DemoResp> getPostParamResult(@RequestParam(value = "name")String name);

    @RequestMapping(value = "getPostParamEntityResult",method = RequestMethod.POST)
    ResponseData<DemoResp> getPostParamEntityResult(@RequestBody DemoResp resp);



    @Component
    class DefaultFallback implements FeignService {
        @Override
        public ResponseData<String> invoke() {
            throw new RuntimeException();
//            return new ResponseData<String>().setCode("40004").setDesc("服务异常").setData(null);
        }

        @Override
        public String getParam(String name,String age) {
            throw new RuntimeException();
        }

        @Override
        public String getPost() {
            throw new RuntimeException();
        }

        @Override
        public String getPostParam(String name) {
            throw new RuntimeException();
        }

        @Override
        public ResponseData<DemoResp> getPostResult() {
            throw new RuntimeException();
        }

        @Override
        public ResponseData<DemoResp> getPostParamResult(String name) {
            throw new RuntimeException();
        }

        @Override
        public ResponseData<DemoResp> getPostParamEntityResult(DemoResp resp) {

            throw new RuntimeException();
        }
    }
}
